package com.aispeech.task.api.controller.api;

import com.aispeech.task.api.controller.base.Base;
import com.aispeech.task.api.data.form.CreateTaskForm;
import com.aispeech.task.api.service.TaskService;
import com.aispeech.task.common.data.vo.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
public class Task extends Base {
    @Autowired
    TaskService service;

    @GetMapping("/{taskId}/progress")
    public Result progress(@PathVariable String taskId, @RequestParam String productId) {
        return service.progress(taskId, productId);
    }

    @GetMapping("/{taskId}/result")
    public Result result(@PathVariable String taskId, @RequestParam String productId) {
        return service.result(taskId, productId);
    }

    @PostMapping
    public Result createFromBody(@RequestBody CreateTaskForm form, @RequestParam String productId) {
        return service.create(form.toMap(), productId);
    }

    @PostMapping("/create")
    public Result createFromForm(@ModelAttribute CreateTaskForm form, @RequestParam String productId) {
        return service.create(form.toMap(), productId);
    }
}
